<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ page import="com.lczyfz.istep.common.constants.DistributeType" %>
<html>
<head>
	<title>教学管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }

		//配置CTF题目集
		function configCtfSetBox(CtfSetId){
			top.$.jBox("<div class='form-search' style='padding-left:20px; padding-top: 20px; padding-bottom: 15px;'>是否可以查看解题思路</div>"+
					"<div class='form-search' style='padding-left:30px; padding-bottom: 20px;'><input type='radio' id='solutionYes' name='solutionIsAllowRadio' value='1'/>是<br/>"+
					"<input type='radio' id='solutionNo' name='solutionIsAllowRadio' value='0'/>否</div>",
					{
						title: "配置CTF题目集",
						submit: function (v, h, f) {
							$.ajax({
								type: "POST",
								url: "${ctx}/teach/teachDistribute/configCtfSet",
								data: {
									"CtfSetId": CtfSetId,
									"solutionIsAllow": f.solutionIsAllowRadio,
									"teachDistributeId": $("#teachDistributeId").val()
								},
								success:function(res){
									if(res != null && res != ""){
										alertx("成功配置CTF题目集！");
									}
								},
								error:function(){
//									alertx("error");
								}
							});

						}
					});
			return false;
		}

		//先进行判断CTF题目集是否配置，再进行判断试卷是否配置，再进行添加
		function confirmDistribute(){
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachDistribute/configCtfSetOrNot",
				data: {
					"teachDistributeId": $("#teachDistributeId").val(),
					"CtfSetList": $("#CtfSetList").val()
				},
				success:function(jsonModel){
					if(jsonModel.success == false){
						alertx(jsonModel.msg + "还未进行配置！");
					}else{

						$.ajax({
							type: "POST",
							url: "${ctx}/teach/teachDistribute/configPaperOrNot",
							data: {
								"teachDistributeId": $("#teachDistributeId").val(),
								"PaperList": $("#PaperList").val()
							},
							success:function(jsonModel){
								if(jsonModel.success == false){
									alertx(jsonModel.msg + "还未进行配置！");
								}else{
									window.location.href = "${ctx}/teach/teachDistribute/confirmDistribute?teachDistributeId=${teachDistributeId}&&distributeClass=${distributeClass}&&distributeStudent=${distributeStudent}&&CourseSystemList=${CourseSystemList}&&CtfSetList=${CtfSetList}&&PaperList=${PaperList}";
								}
							},
							error:function(){
								console.log("configPaperOrNot_error!")
							}
						});
					}

				},
				error:function(){
					console.log("configCtfSetOrNot_error!")
				}
			});
		}

	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/teach/teachDistribute/">教学管理列表</a></li>
		<shiro:hasPermission name="teach:teachDistribute:edit"><li  class="active"><a href="#">编辑下发</a></li></shiro:hasPermission>
	</ul>
	<form:form id="inputForm" modelAttribute="teachDistribute" action="${ctx}/teach/teachDistribute/confirmDistribute" method="post" class="form-horizontal">
	<sys:message content="${message}"/>
		<%--隐藏域--%>
		<label for="teachDistributeId"></label><input value="${teachDistributeId}" id="teachDistributeId" name="teachDistributeId" type="hidden"/>
		<label for="distributeClass"></label><input value="${distributeClass}"  id="distributeClass" name="distributeClass" type="hidden"/>
		<label for="distributeStudent"></label><input value="${distributeStudent}"  id="distributeStudent" name="distributeStudent" type="hidden"/>
		<label for="CourseSystemList"></label><input value="${CourseSystemList}"  id="CourseSystemList" name="CourseSystemList" type="hidden"/>
		<label for="CtfSetList"></label><input value="${CtfSetList}"  id="CtfSetList" name="CtfSetList" type="hidden"/>
		<label for="PaperList"></label><input value="${PaperList}"  id="PaperList" name="PaperList" type="hidden"/>

	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>已选择下发内容</th>
				<th>下发类型</th>
				<shiro:hasPermission name="teach:teachDistribute:edit"><th>配置</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${CourseSystem}" var="CourseSystem">
			<tr>
				<td>
					${CourseSystem.coursesystemName}
				</td>
				<td>
					<%=DistributeType.CourseSystem%>
				</td>
				<td>
					<%=DistributeType.None%>
				</td>
	 	</tr>
		</c:forEach>
		<c:forEach items="${CtfSet}" var="CtfSet">
			<tr>
				<td>
					${CtfSet.ctfSetName}
				</td>
				<td>
					<%=DistributeType.CtfSet%>
				</td>
				<td>
					<a href="javascript:configCtfSetBox('${CtfSet.id}')">配置</a>
				</td>
			</tr>
		</c:forEach>
		<c:forEach items="${Paper}" var="Paper">
			<tr>
				<td>
					${Paper.paperName}
				</td>
				<td>
					<%=DistributeType.Paper%>
				</td>
				<td>
					<a href="${ctx}/teach/teachDistribute/configPaperForm?teachDistributeId=${teachDistributeId}&&paperId=${Paper.id}&&distributeClass=${distributeClass}&&distributeStudent=${distributeStudent}&&CourseSystemList=${CourseSystemList}&&CtfSetList=${CtfSetList}&&PaperList=${PaperList}">配置</a>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="form-actions">
		<%--<a href="${ctx}/teach/teachDistribute/form" class="btn">返 回</a>--%>
		<%--<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>--%>
		<%--<shiro:hasPermission name="teach:teachDistribute:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="添 加" />&nbsp;</shiro:hasPermission>--%>
		<shiro:hasPermission name="teach:teachDistribute:edit"><a class="btn btn-primary" href="javascript:confirmDistribute()">确认下发</a></shiro:hasPermission>
	</div>
	<div class="pagination">${page}</div>
	</form:form>

</body>
</html>